home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABUControls.c
-
- NAME
- ABUControls.c, part of the ABox project source code,
- responsible for mix-in handling the AboutBox Controls stuff.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 14 June 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
-
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABUControls.h"
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
-
- /*=============================== ABUControls::ABUControls ================================*/
- ABUControls::ABUControls(void)
- {
- cList = NULL;
- cNumber = 0;
- } // end ABUControls
-
-
- /*=============================== ABUControls::~ABUControls ================================*/
- ABUControls::~ABUControls(void)
- {
- if (cList)
- {
- DisposPtr((Ptr)cList);
- cList = NULL;
- }
- cNumber = 0;
-
- } // end ~ABUControls
-
-
-
-
-
- /*=============================== ABUControls::FlashControl ===============================*/
- //
- // FlashControl will simulate a user-click on the
- // control specified. Specifically, it simulates the visual
- // aspects of a user clicking or selecting a control...useful when
- // intercepting events in an event filter proc.
- //
- // based upon DialogBits by CK Haun, Apple Dev Tech Suppt.
- //
- //
- // is called by:
- // DoEvent
- //
- Boolean ABUControls::FlashControl (ControlHandle ctrl)
- {
- Boolean active = false;
- long timer;
- const long duration = 8;
-
- if (ctrl)
- {
- active = IsControlActive(ctrl);
- if (active)
- {
- HiliteControl(ctrl, true);
- Delay(duration, &timer); // wait about 8 ticks so they can see it
- HiliteControl(ctrl, false);
- }
- } // end if block
-
- return active;
- } // end of function FlashControl()
-
-
-
-
- /*=============================== ABUControls::IsControlActive ===============================*/
- //
- // IsControlActive will return a value of either true or
- // false, indicative of whether the given control is indeed
- // active or not.
- //
- //
- // is called by:
- Boolean ABUControls::IsControlActive (ControlHandle ctrl)
- {
- if (ctrl)
- if ((*ctrl)->contrlHilite == kABdeactivateControl)
- return false;
- else
- return true;
- else
- return false;
- } // end IsControlActive()
-
-
-
-
-
- /*=============================== ABUControls::CheckControl ===============================*/
- //
- // CheckControl will set/unset a control.
- //
- //
- // is called by:
- OSErr ABUControls::CheckControl (ControlHandle ctrl, Boolean setCondition)
- {
- if (ctrl)
- {
- HiliteControl (ctrl, (setCondition ? kABactivateControl : kABdeactivateControl));
- return noErr;
- } else {
- return paramErr;
- } // end if else block
-
- } // end CheckControl()
-
-
-
-
-
- /*=============================== ABUControls::CheckAllControls ===============================*/
- //
- // CheckAllControls will set/unset all the controls in a window.
- //
- //
- // is called by:
- OSErr ABUControls::CheckAllControls (WindowPtr theWindow, Boolean setCondition)
- {
- ControlHandle ctrlHandle = NULL;
- OSErr error = noErr;
-
- // begin here...
-
- if (theWindow)
- {
- // nothing, so check to see if we can walk the
- // window's control list and find the nth control
- ctrlHandle = ((WindowPeek)theWindow)->controlList;
-
- while (ctrlHandle)
- {
- error = CheckControl (ctrlHandle, setCondition);
- ctrlHandle = (*ctrlHandle)->nextControl;
- } // end while loop
- } else {
- error = paramErr;
- } // end if else block
-
- return error;
- } // end CheckAllControls()
-
-
-
-
-
- /*=============================== ABUControls::GetControlHandle ===============================*/
- //
- // GetControlHandle will return a handle to a given control item
- // in the given dialog box. If the item is _not_ a control then
- // a kABbadControlHandle is returned.
- //
- // based upon SnatchHandle() by CK Haun, Apple Dev Tech Suppt.
- //
- // Handy for setting checkboxes and radio buttons
- //
- //
- // is called by:
- //
- ControlHandle ABUControls::GetControlHandle (GrafPtr window, short theGetItem)
- {
- short index = 1;
- short itemType;
- Rect itemRect;
- Handle itemHandle = NULL;
- ControlHandle ctrlHandle = NULL;
-
- if (!(window && (theGetItem > 0)))
- {
- return NULL;
- } // end if block
-
- GetDItem(window, theGetItem, &itemType, &itemHandle, &itemRect);
-
- if (itemHandle)
- {
- // GetDItem returned something...
-
- ctrlHandle = (ControlHandle)itemHandle;
- if (!(itemType & ctrlItem))
- {
- ctrlHandle = NULL;
- } // end if else block
- } else {
- // nothing, so check to see if we can walk the
- // window's control list and find the nth control
- ctrlHandle = ((WindowPeek)window)->controlList;
-
- while (ctrlHandle && (index != theGetItem))
- {
- ctrlHandle = (*ctrlHandle)->nextControl;
- ++index;
- } // end while loop
-
- if (index != theGetItem)
- ctrlHandle = NULL;
-
- } // end if block
-
- return ctrlHandle;
-
- } // end of function GetControlHandle
-
-
-
-
- /*=============================== ABUControls::CountControls ===============================*/
- //
- // CountControls will count the number of control items in the given window.
- //
- short ABUControls::CountControls (WindowPtr window)
- {
- short number = 0;
- ControlHandle ctrl = NULL;
-
- // begin here...
-
- if (!window)
- return number;
-
- ctrl = ((WindowPeek)window)->controlList;
- while (ctrl)
- {
- ++number;
- ctrl = (*ctrl)->nextControl;
- } // end while loop
-
- return number;
- } // end CountControls
-
-
-
-
-
- /*=============================== ABUControls::SaveControlStates ===============================*/
- //
- // SaveControlStates will save the states of all controls in the given
- // window, for restoration later.
- //
- OSErr ABUControls::SaveControlStates (WindowPtr window)
- {
- OSErr error = noErr;
- ControlHandle ctrl = NULL;
- short index;
-
- // begin here...
-
- if (!window)
- return paramErr;
-
- if (cList)
- {
- DisposPtr((Ptr)cList);
- cList = NULL;
- cNumber = 0;
- } // end if block
-
- cNumber = CountControls(window);
-
- if (!cNumber)
- {
- return paramErr;
- } else {
- cList = (ABControlListPtr)NewPtrClear (cNumber * sizeof(ABControlList));
- error = MemError();
- } // end if else block
-
- if (error)
- return error;
-
- ctrl = ((WindowPeek)window)->controlList;
- index = 0;
- while (ctrl)
- {
- cList[index].handle = ctrl;
- cList[index].state = (*ctrl)->contrlHilite;
- ++index;
- ctrl = (*ctrl)->nextControl;
- } // end while loop
-
- return error;
- } // end SaveControlStates
-
-
-
-
-
- /*=============================== ABUControls::RestoreControlStates ===============================*/
- //
- // RestoreControlStates will save the states of all controls in the given
- // window, for restoration later.
- //
- OSErr ABUControls::RestoreControlStates (WindowPtr window)
- {
- OSErr error = noErr;
- short index;
-
- // begin here...
-
- if (!(window && cList && cNumber))
- return paramErr;
-
- for (index = 0; index < cNumber; ++index)
- {
- HiliteControl(cList[index].handle, cList[index].state);
- } // end for loop
-
- return error;
- } // end RestoreControlStates
-
-
-
-
- // end of file.
-
-
-
-